package com.chenliang.controller;

import com.chenliang.domain.Orders;
import com.chenliang.service.IOrdersService;
import com.chenliang.service.IService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @ProjectName: mavenSSM
 * @Package: com.chenliang.controller
 * 作用：
 */
@Controller
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private IOrdersService service;

    @RequestMapping("/findAll")
    public String findAll(Model model,
        @RequestParam(name = "page", defaultValue = "1", required = true) Integer page,
        @RequestParam(name = "pageSize", defaultValue = "3", required = true) Integer pageSize) {
        List<Orders> orders = service.findAll(page, pageSize);
        PageInfo pageInfo = new PageInfo(orders);
        model.addAttribute(pageInfo);
        return "orders-list";
    }

    @RequestMapping("/findShow")
    public ModelAndView findshow(String id) {
        Orders orders = service.findShow(id);
        ModelAndView mv = new ModelAndView();
        mv.addObject("orders", orders);
        mv.setViewName("orders-show");
        return mv;
    }

}
